Blockly.Blocks['Goertek_TakeOff'] = {
  init: function() {
    this.appendDummyInput()
        .appendField("起飞 ")
        .appendField("plane")
        .appendField(new Blockly.FieldTextInput("f1"), "plane")
        .appendField("alt(cm)")
        .appendField(new Blockly.FieldTextInput("100"), "alt");
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(250);
    this.setTooltip('');
    this.setHelpUrl('http://www.example.com/');
  }
};
Blockly.Python['Goertek_TakeOff'] = function(block) {
  // TODO: Assemble Python into code variable.
  var getvalue = block.getFieldValue('plane');
  var alt = block.getFieldValue('alt');
  var code = 'TakeOff('+getvalue+','+alt+')'+'\n';
  return code;
};

Blockly.Blocks['Goertek_Landing'] = {
  init: function() {
    this.appendDummyInput()
        .appendField("降落 ")
        .appendField("plane")
        .appendField(new Blockly.FieldTextInput("f1"), "land");
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(250);
    this.setTooltip('');
    this.setHelpUrl('http://www.example.com/');
  }
};
Blockly.Python['Goertek_Landing'] = function(block) {
  // TODO: Assemble Python into code variable.
  var getvalue = block.getFieldValue('land');
  var code = 'Land('+getvalue+')'+'\n';
  return code;//返回的函数
};

Blockly.Blocks['Goertek_Roll'] = {
  init: function() {
    this.appendDummyInput()
        .appendField("翻转")
        .appendField("plane")
        .appendField(new Blockly.FieldTextInput("f1"), "plane")
        .appendField("pitch")
        .appendField(new Blockly.FieldTextInput("0"), "pitch")
        .appendField("roll")
        .appendField(new Blockly.FieldTextInput("0"), "roll")
        .appendField("yaw")
        .appendField(new Blockly.FieldTextInput("0"), "yaw");
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(250);
    this.setTooltip('');
    this.setHelpUrl('http://www.example.com/');
  }
};
Blockly.Python['Goertek_Roll'] = function(block) {
  var text_pitch = block.getFieldValue('pitch');
  var text_roll = block.getFieldValue('roll');
  var text_yaw = block.getFieldValue('yaw');
  var plane = block.getFieldValue('plane');
  // TODO: Assemble Python into code variable.
  var code = 'Goertek_Roll('+plane+','+text_pitch+','+text_roll+','+text_yaw+')\n';
  return code;
};

Blockly.Blocks['Goertek_Advance'] = {
  init: function() {
    this.appendDummyInput()
        .appendField("前进 ")
        .appendField("plane")
        .appendField(new Blockly.FieldTextInput("f1"), "plane")
        .appendField("Vx(m)")
        .appendField(new Blockly.FieldTextInput("0"), "advance");
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(250);
    this.setTooltip('');
    this.setHelpUrl('http://www.example.com/');
  }
};
Blockly.Python['Goertek_Advance'] = function(block) {
  var getair = block.getFieldValue('plane');
  var text_advance = block.getFieldValue('advance');
  // TODO: Assemble Python into code variable.
  var code = 'Displacement_Delta('+getair+','+text_advance+','+'0'+','+'0'+')\n';
  return code;
};

Blockly.Blocks['Goertek_Retreat'] = {
  init: function() {
    this.appendDummyInput()
        .appendField("后退 ")
        .appendField("plane")
        .appendField(new Blockly.FieldTextInput("f1"), "plane")
        .appendField("Vx(m)")
        .appendField(new Blockly.FieldTextInput("0"), "retreat");
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(250);
    this.setTooltip('');
    this.setHelpUrl('http://www.example.com/');
  }
};
Blockly.Python['Goertek_Retreat'] = function(block) {
  var getair = block.getFieldValue('plane');
  var text_retreat = block.getFieldValue('retreat');
  // TODO: Assemble Python into code variable.
  var code = 'Displacement_Delta('+getair+','+text_retreat+','+'0'+','+'0'+')\n';
  return code;
};

Blockly.Blocks['Goertek_TurnLeft'] = {
  init: function() {
    this.appendDummyInput()
        .appendField("向左 ")
        .appendField("plane")
        .appendField(new Blockly.FieldTextInput("f1"), "plane")
        .appendField("Vy(m)")
        .appendField(new Blockly.FieldTextInput("0"), "turnleft");
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(250);
    this.setTooltip('');
    this.setHelpUrl('http://www.example.com/');
  }
};
Blockly.Python['Goertek_TurnLeft'] = function(block) {
  var getair = block.getFieldValue('plane');
  var text_turnleft = block.getFieldValue('turnleft');
  // TODO: Assemble Python into code variable.
  var code = 'Displacement_Delta('+getair+','+'0'+','+text_turnleft+','+'0'+')\n';
  return code;
};

Blockly.Blocks['Goertek_TurnRight'] = {
  init: function() {
    this.appendDummyInput()
        .appendField("向右 ")
        .appendField("plane")
        .appendField(new Blockly.FieldTextInput("f1"), "plane")
        .appendField("Vy(m)")
        .appendField(new Blockly.FieldTextInput("0"), "turnright");
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(250);
    this.setTooltip('');
    this.setHelpUrl('http://www.example.com/');
  }
};
Blockly.Python['Goertek_TurnRight'] = function(block) {
  var getair = block.getFieldValue('plane');
  var text_turnright = block.getFieldValue('turnright');
  // TODO: Assemble Python into code variable.
  var code = 'Displacement_Delta('+getair+','+'0'+','+text_turnright+','+'0'+')\n';
  return code;
};

Blockly.Blocks['Goertek_GoUp'] = {
  init: function() {
    this.appendDummyInput()
        .appendField("上升 ")
        .appendField("plane")
        .appendField(new Blockly.FieldTextInput("f1"), "plane")
        .appendField("Vz(m)")
        .appendField(new Blockly.FieldTextInput("0"), "goup");
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(250);
    this.setTooltip('');
    this.setHelpUrl('http://www.example.com/');
  }
};
Blockly.Python['Goertek_GoUp'] = function(block) {
  var getair = block.getFieldValue('plane');
  var text_goup = block.getFieldValue('goup');
  // TODO: Assemble Python into code variable.
  var code = 'Displacement_Delta('+getair+','+'0'+','+'0'+','+text_goup+')\n';
  return code;
};

Blockly.Blocks['Goertek_Descend'] = {
  init: function() {
    this.appendDummyInput()
        .appendField("下降 ")
        .appendField("plane")
        .appendField(new Blockly.FieldTextInput("f1"), "plane")
        .appendField("Vz(m)")
        .appendField(new Blockly.FieldTextInput("0"), "descend");
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(250);
    this.setTooltip('');
    this.setHelpUrl('http://www.example.com/');
  }
};
Blockly.Python['Goertek_Descend'] = function(block) {
  var getair = block.getFieldValue('plane');
  var text_descend= block.getFieldValue('descend');
  // TODO: Assemble Python into code variable.
  var code = 'Displacement_Delta('+getair+','+'0'+','+'0'+','+text_descend+')\n';
//  var fso = new ActiveXObject("Scripting.FileSystemObject"); 
//	fso.CreateTextFile("E:\\test.py",true);   
//    file = fso.GetFile("E:\\test.py");
//    alert(fso.GetFileName(file));
//    ts = file.OpenAsTextStream(2,true);   
//    ts.WriteLine(code);   
//    ts.WriteLine('呵呵'); 
//    ts.Close(); //保存到后台的txt格式，需要什么代码自己写；
  return code;
};

Blockly.Blocks['Goertek_UnLock'] = {
  init: function() {
    this.appendDummyInput()
        .appendField("解锁 ")
        .appendField("plane")
        .appendField(new Blockly.FieldTextInput("f1"), "plane");
    this.setNextStatement(true, null);
    this.setColour(250);
    this.setTooltip('');
    this.setHelpUrl('http://www.example.com/');
  } 
};
Blockly.Python['Goertek_UnLock'] = function(block) {
  // TODO: Assemble Python into code variable.
  var Arm = block.getFieldValue('plane');
  var code ='Arm('+Arm+','+'1'+')'+'\n';
  return code;
};

Blockly.Blocks['Goertek_Lock'] = {
  init: function() {
    this.appendDummyInput()
        .appendField("上锁 ")
        .appendField("plane")
        .appendField(new Blockly.FieldTextInput("f1"), "plane");
    this.setPreviousStatement(true, null);
    this.setColour(250);
    this.setTooltip('');
    this.setHelpUrl('http://www.example.com/');
  }
};
Blockly.Python['Goertek_Lock'] = function(block) {
  // TODO: Assemble Python into code variable.
  var Disarm = block.getFieldValue('plane');
  var code ='Arm('+Disarm+','+'0'+')'+'\n';
  return code;
};

Blockly.Blocks['goertek_accl'] = {
  init: function() {
    this.appendDummyInput()
        .appendField("油门")
        .appendField("plane")
        .appendField(new Blockly.FieldTextInput("f1"), "plane")
        .appendField("accelerograph")
        .appendField(new Blockly.FieldTextInput("0"), "zhuan");
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(250);
    this.setTooltip('');
    this.setHelpUrl('http://www.example.com/');
  }
};
Blockly.Python['goertek_accl'] = function(block) {
  var text_plane = block.getFieldValue('plane');
  var text_zhuan = block.getFieldValue('zhuan');
  // TODO: Assemble Python into code variable.
  var code = 'accl('+text_plane+','+text_zhuan+')\n';
  return code;
};


